<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

class QuizItem extends JsonResource
{
    protected static $isPublic = false;

    /**
     * @param mixed $resource
     * @param bool $isPublic
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public static function collection($resource, $isPublic = false)
    {
        self::$isPublic = $isPublic;
        return parent::collection($resource);
    }

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'odds' => $this->odds,
            'status' => $this->status,
            'result' => $this->result,
            'count' => self::$isPublic ? $this->cachedCount : [],
            'current_bets' => $this->currentBets,
        ];
    }
}
